package de.dlrg.wms.model;

import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import org.hibernate.validator.constraints.NotEmpty;

import de.dlrg.wms.model.NullClasses.AgeClassNull;

@javax.persistence.Entity
public class Swimmer {
	public static Swimmer SwimmerNull = new de.dlrg.wms.model.NullClasses.SwimmerNull();

	private static final long serialVersionUID = -8746935958414979195L;

	@OneToOne(fetch = FetchType.EAGER)
	private AgeClass ageClass = AgeClass.AgeClassNull;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@NotEmpty(message = "A swimmer needs a name")
	private String name = "";
	@NotEmpty(message = "A swimmer needs a surname")
	private String surName = "";

	public AgeClass getAgeClass() {
		return ageClass;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getSurName() {
		return surName;
	}

	public Swimmer setAgeClass(AgeClass ageClass) {
		this.ageClass = ageClass;
		return this;
	}

	public Swimmer setId(Long id) {
		this.id = id;
		return this;
	}

	public Swimmer setName(String name) {
		this.name = name;
		return this;
	}

	public Swimmer setSurName(String surName) {
		this.surName = surName;
		return this;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof de.dlrg.wms.model.NullClasses.SwimmerNull) {
			return false;
		}
		if (obj instanceof Swimmer) {
			Swimmer swimmer = (Swimmer) obj;
			boolean ret = (swimmer.getId().equals(this.getId()));
			return ret;
		}
		return super.equals(obj);
	}

	@Override
	public String toString() {
		return this.name + "," + this.surName;
	}
}
